'use strict';

/**
 * @ngdoc function
 * @name webApp.controller:MainCtrl
 * @description
 * # MainCtrl
 * Controller of the webApp
 */

angular.module('webApp')
  .controller('mainController', function ($scope,jqLite,$location,$timeout,browser,popBox,$localStorage) {
  $scope.$on('$stateChangeSuccess',function(){
    //工具盒子
    $scope.toolBox = false;
    $timeout(function(){
      $scope.toolBox = true;
    });
    jqLite.$('footer ').removeClass('heightAdd');
    $scope.revise = '';
    jqLite.$('reply').removeClass('as');
    //回退按钮的隐藏
    if($location.$$path == '/root/home' || $location.$$path == '/root/report' || $location.$$path == '/root/server'){
      $scope.backShow = false;
      $timeout(function(){
        var inner = angular.element(document.getElementsByClassName('title-center'));
        for(var i = 0;i < inner.length;i++){
          if(inner[i].innerHTML == '上海国际航运研究中心'){
            inner[i].innerHTML = '<span class="logo">上海国际航运研究中心</span>'
          }
        }
      });
    }
    else{
      $scope.backShow = true;
    }
  });
  //修改个人信息
  $scope.modify = function(page){
    if(page == 0){
      $scope.mobDes = true;
      $scope.description = '填写你的邮箱让更多人能联系到自己';
    }
    else if(page == 1){
      $scope.mobDes = true;
      $scope.description = '填写你的姓名让更多人认识自己';
    }
    else if(page == 2){
      $scope.mobDes = false;
      $scope.description = ' ';
    }
    else if(page == 3){
      $scope.mobDes = true;
      $scope.description = '填写你的职位让你的朋友更加了解自己';
    }
  };
  //紧急历史回退
  $scope.otherBack = function(){
    var oldRoute = $location.$$path;
    $timeout(function(){
      var newRoute = $location.$$path;
      if(oldRoute == newRoute){
        $location.path('/root/home');
      }
    },1000);
  };

  //警告框
  $scope.$on('rejection',function(ele,data){
    if(data == '远程服务器无法访问！'){
      //window.location = '404.html';
    }
    else{
      popBox.showConfirm('警告',data.data.error_description);
    }
  });
  $scope.$on('401',function(ele,data){
    popBox.showConfirm('警告','登录超时，请重新登录！');
    $localStorage.access_token = null;
    $location.path('/root/signIn');
  });
  //输入框高度
  $scope.boxHeight = {
    'height': (browser.factory()[5] * 0.75 * 0.1324965) + 'px'
  };
});
